import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

// 静态路由,所有人都有菜单
export const constantRoutes = [
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/', // 根路由
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      // meta元信息,用来存储菜单数据
      meta: { title: '功能A', icon: 'dashboard' }
    }]
  }
]

// 动态路由,需要做根据用户角色过滤的菜单
// 路由模块化写法,一个文件就是一个路由选项
import Approvals from './modules/approvals.js'
import Attendances from './modules/attendances.js'
import Salarys from './modules/salarys.js'
import Social from './modules/social.js'

export const asyncRoutes = [
  Approvals, Attendances, Salarys, Social
]
// asyncRoutes.push(asyncRoutes)
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...asyncRoutes]
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router

